package org.seratic.enterprise.movil.chatsocket.com;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;


/**
 *
 * @author david.fernandez
 */
public class ConexionSocketAndroid implements ConexionSocket{
    private Socket sc;
    private DataInputStream is;
    private DataOutputStream os;

    public void conectar(String host,int puerto) throws Exception {
    	InetAddress addr = InetAddress.getByName(host);
    	InetSocketAddress socketAddress = new InetSocketAddress(addr, puerto);
        sc= new Socket();
        sc.connect(socketAddress);
        is= new DataInputStream(sc.getInputStream());
        os= new DataOutputStream(sc.getOutputStream());
    }

    public DataInputStream getDataInputStream() {
        return is;
    }

    public DataOutputStream getDataOutputStream() {
        return os;
    }

    public void cerrar() {
        try {
            if (is!=null)
                is.close();
            if (os!=null)
                os.close();
            if (sc!=null)
                sc.close();
            //sc.shutdownInput();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}
